<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/5/11
  Time: 9:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css" type="text/css"/>
    <link rel="stylesheet" href="/plugins/adminLte/css/AdminLTE.min.css">
    <link rel="stylesheet" href="/css/global.css">
    <script type="text/javascript" src="/plugins/jquery.min.js"></script>
    <script type="text/javascript" src="/js/core/helper.js"></script>
    <script src="/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="/js/core/building_utils.min.js?v=69"></script>
</head>
<body>
<div class="box box-primary">
    <div class="box-frame">
        <div class="box-header with-border">
            <h4 class="box-title">公告信息列表</h4>
        </div>
        <div class="box-body">
        <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">小区信息</label>
                <div class="layui-input-inline">
                    <select name="selectComm" id="selectComm" lay-filter="selectComm">
                        <option value="">请请选小区</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="selectBuilding" id="selectBuilding" lay-filter="selectBuilding">
                        <option value="">请选择楼栋</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="selectUnit" id="selectUnit" lay-filter="selectUnit">
                        <option value="">请选择单元</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="selectFloor" id="selectFloor" lay-filter="selectFloor">
                        <option value="">请选择楼栋</option>
                    </select>
                </div>
                <div class="layui-input-inline">
                    <select name="selectRoom" id="selectRoom" lay-filter="selectRoom">
                        <option value="">请选择房号</option>
                    </select>
                </div>
                <button class="layui-btn" lay-submit="" lay-filter="query">查询</button>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">标题查询</label>
                <div class="layui-input-block" style="max-width: 986px">
                    <input type="text" name="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
                </div>
            </div>

            <div class="layui-form-pane" style="margin-top: 15px;">
                <div class="layui-form-item">
                    <div class="layui-tab-item layui-show layui-table-responsive">
                        <table class="layui-table">
                            <colgroup>
                                <col width="250">
                                <col width="180">
                                <col width="250">
                                <col>
                                <col width="150">
                                <col width="150">
                            </colgroup>
                            <thead>
                            <tr>
                                <th>标题</th>
                                <th>发布时间</th>
                                <th>有效期</th>
                                <th>发布对象</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody id="tbody"></tbody>
                        </table>
                        <div id="page"></div>
                        <div style="clear: both"></div>
                    </div>
                </div>
            </div>
        </form>
        </div>
    </div>
</div>

<script>
    var form;
    layui.use(['form', 'laypage', 'layedit', 'laydate'], function () {
        form = layui.form();
        form.on('submit(query)', function (data) {
            queryNoticeList(1);
            return false;
        });
        form.on('submit(see)', function (data) {
            queryNoticeList(1);
            return false;
        });
        setSelectComm(true, function () {
            queryNoticeList(1);
        });
    });

    var modelParam = {};
    modelParam.pageSize = 10;
    modelParam.currentSize = 1;

    function queryNoticeList(page) {
        var title = $("input[name='title']").val();
        var commCode = $("select[name='selectComm']").val();
        var building = $("select[name='selectBuilding']").val();
        var unit = $("select[name='selectUnit']").val();
        var floor = $("select[name='selectFloor']").val();
        var room = $("select[name='selectRoom']").val();

        var param = {};
        param.pageSize = modelParam.pageSize;
        param.page = page;
        param.title = title;
        param.commCode = commCode;
        param.equType = commCode + building + unit + floor + room;
        postJson("/NoticeCtrl/queryNoticePage.x", $.param(param), function (data) {
            $('#tbody').empty();
            render(data.list);
            layui.laypage({
                cont: 'page'
                , pages: Math.ceil(data.size / modelParam.pageSize)
                , jump: function (row, first) {
                    if (!first) {
                        modelParam.currentSize = row.curr;
                        param.page = row.curr;
                        queryPage(param);
                    }
                }
            });
        });
    }

    function render(list) {
        $('#tbody').append();
        for (var i in list) {
            var isShow = '';
            if (list[i].isShow) {
                isShow = '<i class="fa fa-arrows-alt"></i>&nbsp;正在展示';
            }
            $('#tbody').append(
                '<tr>' +
                '<td>' + list[i].titile + '</td>' +
                '<td>' + list[i].create_time + '</td>' +
                '<td>' + list[i].begin_date + '&nbsp;至&nbsp;' + list[i].end_date + '</td>' +
                '<td>' + list[i].putObject + '</td>' +
                '<td>' + isShow + '</td>' +
                '<td>' +
                '<button class="layui-btn layui-btn-small layui-btn-danger" onClick="deleteNotice(\'' + list[i].notice_code + '\');return false;">删除</button> ' +
                '<button class="layui-btn layui-btn-small layui-btn-normal" onClick="seeNotice(\'' + list[i].notice_code + '\');return false;">查看</button></td>' +
                '</tr>'
            );
        }
    }

    function queryPage(param) {
        postJson("/NoticeCtrl/queryNoticePage.x", $.param(param),
            function (data) {
                $('#tbody').empty();
                render(data.list);
            });
    }

    function deleteNotice(noticeCode) {
        layer.confirm('确定要删除此通知？', {
            btn: ['确定', '取消']
        }, function () {
            var param = {
                noticeCode: noticeCode
            };
            postJson("/NoticeCtrl/remove.x", $.param(param), function (data) {
                queryNoticeList(modelParam.currentSize);
                layer.msg('&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;删除成功', {icon: 6});
            });
        });
    }

    function seeNotice(noticeCode) {
        layui.layer.open({
            title: '通知详情',
            type: 2,
            area: ['800px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: '/NoticeCtrl/view.x?noticeCode=' + noticeCode
        });
    }
</script>

</body>
</html>
